# SPDX-License-Identifier: GPL-2.0+
# This Containerfile is used to build an image containing basic stuff to be used
# to build barebox and run our test suites.

FROM debian:bookworm
MAINTAINER Sascha Hauer <s.hauer@pengutronix.de>
LABEL Description="This image is for building and testing barebox inside a container"

# Make sure apt is happy
ENV DEBIAN_FRONTEND=noninteractive

# Update and install things from apt now
RUN apt-get update && apt-get install -y \
	bison \
	build-essential \
	coreutils \
	flex \
	gawk \
	git \
	imagemagick \
	libc6-i386 \
	libgit2-dev \
	libguestfs-tools \
	liblz4-tool \
	libseccomp-dev \
	libssl-dev \
	libtool \
	libudev-dev \
	libusb-1.0-0-dev \
	lzma-alone \
	lzop \
	mount \
	openssl \
	pkg-config \
	util-linux \
	wget \
	qemu-system-arm \
	qemu-system-misc \
	qemu-system-mips \
	qemu-system-x86 \
	qemu-system-common \
	ovmf \
	python3 \
	python3-pip \
	python3-virtualenv \
	python3-setuptools \
	python3-libfdt \
	virtualenv \
	sudo \
	u-boot-tools \
	&& rm -rf /var/lib/apt/lists/*

ENV GCC_VERSION=14.2.0

# Manually install the kernel.org Crosstool based toolchains
RUN korg_crosstool_dl() { wget -nv -O - https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/${1}/${2}/${1}-gcc-${2}-nolibc-${3}.tar.xz | tar -C /opt -xJ ; } && \
    korg_crosstool_dl x86_64 ${GCC_VERSION} arm-linux-gnueabi && \
    korg_crosstool_dl x86_64 ${GCC_VERSION} aarch64-linux     && \
    korg_crosstool_dl x86_64 ${GCC_VERSION} mips-linux        && \
    korg_crosstool_dl x86_64 13.1.0         or1k-linux        && \
    korg_crosstool_dl x86_64 ${GCC_VERSION} powerpc-linux     && \
    korg_crosstool_dl x86_64 ${GCC_VERSION} riscv64-linux

RUN wget -nv -O kvx.tgz https://github.com/kalray/build-scripts/releases/download/v5.0.0/gcc-kalray-kvx-ubuntu-22.04-v5.0.0.tar.gz

RUN echo "d27b3d6e6246f5debffee0bb01e77eb133bd32c658782a68a779cf9fb4c436bc kvx.tgz" | \
    sha256sum --check --status

RUN tar -C /opt -xzf kvx.tgz && rm kvx.tgz

RUN wget -nv "https://github.com/qemu/qemu/blob/v5.2.0/pc-bios/opensbi-riscv32-generic-fw_dynamic.bin?raw=true" -O /usr/share/qemu/opensbi-riscv32-generic-fw_dynamic.bin

# Create our user/group
RUN useradd -m -U barebox
RUN echo barebox ALL=NOPASSWD: ALL > /etc/sudoers.d/barebox

# install labgrid
RUN cd /tmp && \
    git clone --depth 1 -b v24.0 https://github.com/labgrid-project/labgrid && \
    cd labgrid && \
    pip3 install --break-system-packages . && \
    ln -s $(which pytest) /usr/local/bin/labgrid-pytest;

ENV CROSS_COMPILE_arm=/opt/gcc-${GCC_VERSION}-nolibc/arm-linux-gnueabi/bin/arm-linux-gnueabi-
ENV CROSS_COMPILE_arm64=/opt/gcc-${GCC_VERSION}-nolibc/aarch64-linux/bin/aarch64-linux-
ENV CROSS_COMPILE_mips=/opt/gcc-${GCC_VERSION}-nolibc/mips-linux/bin/mips-linux-
ENV CROSS_COMPILE_openrisc=/opt/gcc-13.1.0-nolibc/or1k-linux/bin/or1k-linux-
ENV CROSS_COMPILE_powerpc=/opt/gcc-${GCC_VERSION}-nolibc/powerpc-linux/bin/powerpc-linux-
ENV CROSS_COMPILE_riscv=/opt/gcc-${GCC_VERSION}-nolibc/riscv64-linux/bin/riscv64-linux-
ENV CROSS_COMPILE_kvx=/opt/gcc-kalray-kvx-v5.0.0/bin/kvx-elf-

USER barebox:barebox
